using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace Eva.DBService.DTO
{
    public class ClasseDTO
    {
        /// 
        /// Creates xml string from given dto.
        /// 
        /// DTO
        /// XML
        public string SerializeDTO()
        {
            try
            {
                XmlSerializer xmlSer = new XmlSerializer(this.GetType());
                StringWriter sWriter = new StringWriter();
                // Serialize the dto to xml.
                xmlSer.Serialize(sWriter, this);
                // Return the string of xml.
                return sWriter.ToString();
            }
            catch(Exception ex)
            {
                // Propogate the exception.
                throw ex;
            }
        }

        /// 
        /// Deserializes the xml into a specified data transfer object.
        /// 
        /// string of xml
        /// type of dto
        /// DTO
        public ClasseDTO DeserializeXml(string xml)
        {
            try
            {
                XmlSerializer xmlSer = new XmlSerializer(this.GetType());
                // Read the XML.
                StringReader sReader = new StringReader(xml);
                // Cast the deserialized xml to the type of dto.
                ClasseDTO retDTO = (ClasseDTO)xmlSer.Deserialize(sReader);
                // Return the data transfer object.
                return retDTO;
            }
            catch(Exception ex)
            {
                // Propogate the exception.
                throw ex;
            }            
        }

    }
}
